package cqie.personal.frame.controller;


import cqie.personal.frame.bo.GetBO;
import cqie.personal.frame.entity.CourseInfo;
import cqie.personal.frame.enums.Code;
import cqie.personal.frame.exception.ValidationFailException;
import cqie.personal.frame.service.CourseInfoService;
import cqie.personal.frame.vo.PageVO;
import cqie.personal.frame.vo.ResultVO;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author Yeeeeee
 * @since 2021-09-28
 */
@RestController
@RequestMapping("/course-info")
public class CourseInfoController {
    @Resource
    private CourseInfoService courseInfoService;

    @ApiOperation("Get course info")
    @GetMapping("/getCourseInfo")
    public ResultVO getCourseInfo(GetBO getBO) throws ValidationFailException {
        PageVO<List<CourseInfo>> result = courseInfoService.getCourse(getBO);
        if(result!=null){
            if(result.getRecordCount()>0){
                return new ResultVO(result);
            }
            return new ResultVO(Code.NULL_DATA.getCode(),Code.NULL_DATA.getMessage());
        }
        return new ResultVO(Code.OPERATION_FAIL.getCode(),Code.OPERATION_FAIL.getMessage());
    }


    @ApiOperation("Get All course info")
    @GetMapping("/getAllCourseInfo")
    public ResultVO getAllCourseInfo(GetBO getBO) throws ValidationFailException {
        PageVO<List<CourseInfo>> result = courseInfoService.getClassCourse(getBO);
        if(result!=null){
            if(result.getRecordCount()>0){
                return new ResultVO(result);
            }
            return new ResultVO(Code.NULL_DATA.getCode(),Code.NULL_DATA.getMessage());
        }
        return new ResultVO(Code.OPERATION_FAIL.getCode(),Code.OPERATION_FAIL.getMessage());
    }


}

